package com.example.orderform.contorller;

import com.example.orderform.server.EvaluateServer;
import com.example.orderform.vo.Comments;
import com.example.orderform.vo.CommentsS2;
import com.example.orderform.vo.Order;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

@RestController

@Api
public class EvaluateContorller {
    @Autowired
    EvaluateServer evaluateServer;
    @ApiOperation("评价")
    @RequestMapping("/evaluatecha")

    public List<Order> evaluatecha(@RequestParam("q") int q,
                                   @RequestParam("j") int j,
                                   @RequestParam("userid") int userid){
        List<Order>orderList=evaluateServer.evaluatecha(q,j,userid);
        if (orderList!=null){
            return orderList;
        }
        return null;
    }



    @ApiOperation("带评价的条数")
    @RequestMapping("/taiochass")

    public int taiochass(
            @RequestParam("userid") int userid){
        return  evaluateServer.evalcha(userid);
    }


    @ApiOperation("评价页面商品详情查")
    @RequestMapping("/evaorderxq")

    public Order evaorderxq(@RequestParam("orderid")int orderid){


        Order order=evaluateServer.evaorderxq(orderid);
        return order;
    }

//    @ApiOperation("新增评论")
//    @RequestMapping("/xingzpinl")
//    @ResponseBody
//    public int xingzpinl(
//            @RequestParam("orderid") int orderid,
//            @RequestParam("evaluationgrade") String evaluationgrade,
//            @RequestParam("evaluationcommodity") String evaluationcommodity
//
//    )
//    {
//        System.out.println(orderid);
//        System.out.println(evaluationgrade);
//        System.out.println(evaluationcommodity);
//
//        evaluateServer.xzdd(orderid,evaluationgrade, evaluationcommodity);
//        evaluateServer.gad(orderid);
//        return 1;
//    }
    @ApiOperation("新增评论")
    @RequestMapping("/xingzpinl")

    public int xingzpinl(
            @RequestParam("userid") int userid,
            @RequestParam("spid") int spid,
            @RequestParam("evaluationgrade") String evaluationgrade,
            @RequestParam("evaluationcommodity") String evaluationcommodity,

            @RequestParam("jibie") String jibie,
            @RequestParam("oneID") int oneID


    )
    {
        System.out.println(spid);
        System.out.println(userid);
        System.out.println(evaluationgrade);
        System.out.println(evaluationcommodity);
        System.out.println(jibie);
        System.out.println(oneID);
        int dengji=0;

        if (evaluationgrade=="好评"){
            dengji=1;
        }else if (evaluationgrade=="中评"){
            dengji=2;
        }else if (evaluationgrade=="差评"){
            dengji=3;
        }
        if (jibie==""){
            evaluateServer.neipinl(spid,userid,oneID,evaluationcommodity,new Date());
            return 1;
        }
        if (jibie=="一级"){
            evaluateServer.waipinl(userid,spid,evaluationcommodity,1,dengji,new Date());
            return 1;
        }


        return 0;
    }


    @RequestMapping("/commentsS")
    public List<Comments> commentsS(
            @RequestParam("userid") int userid,
            @RequestParam("spid") int spid
    ){
        System.out.println(userid+"==="+spid);

        System.out.println("hao");
        List<Comments> list=evaluateServer.commentsS(userid, spid);
        if (list!=null){
            return list;
        }
        return null;



    }

    @RequestMapping("/commentsS2")
    public List<CommentsS2> commentsS2(
            @RequestParam("userid") int userid,
            @RequestParam("spid") int spid
    ){
        System.out.println(userid+"==="+spid);

        System.out.println("hao");
        List<CommentsS2> list=evaluateServer.commentsS2(userid, spid);
        if (list!=null){
            return list;
        }
        return null;



    }

//    public void UserTree2(Comments user,List<Comments> users){
////        System.out.println("UserTree2"+user.getId());
//        for (Comments user1 : users) {
////            System.out.println(user1.getId());
////            System.out.println(user1.getChildid());
//            if (user1.getChildid()== user.getId()){
//                user.getChildren().add(user1);
//                UserTree2(user1,users);
//            }
//        }
//
//    }



//    @RequestMapping("/plheti")
//    public Comments plheti(
//
//    ){
//
//
//        System.out.println("plht");
//        List<Comments> list=evaluateServer.plht();
//        Comments comments=new Comments();
//        comments.setChildid(0);
//        UserTree(comments,list);
//        return comments;
//
//
//
//    }
//    int idd=0;
//    public void UserTree(Comments user,List<Comments> users){
////        System.out.println("UserTree2"+user.getId());
//        for (Comments user1 : users) {int orderid=user1.getOrderid();
//            int spid=evaluateServer.selectsp(orderid);
////            System.out.println(user1.getId());
////            System.out.println(user1.getChildid());
//            if (user1.getChildid()== user.getId()){
//
//
//                System.out.println("zi id==="+user.getId());
//                if (user1.getChildid()==0){
//
//                    evaluateServer.waipinl(user1.getUserid(),spid,user1.getEvaluationcommodity(),1,1,user1.getPltime());
//                    idd=evaluateServer.idd(user1.getUserid(),spid,user1.getEvaluationcommodity(),1,1,user1.getPltime());
//                    System.out.println("weiID===="+idd);
//
//                }
//                user.getChildren().add(user1);
//
//            }
//            System.out.println("=========");
//            System.out.println("ID===="+idd);
//            evaluateServer.neipinl(spid,user1.getUserid(),idd,user1.getEvaluationcommodity(),user1.getPltime());
//
//            UserTree2(user1,users);
//        }
//
//    }
}
